﻿using AnesSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// SecondLevelMenuBtn.xaml 的交互逻辑
    /// </summary>
    public partial class SecondLevelMenuBtn : UserControl
    {
        #region Variables

        private bool _isChecked = false;
        private static BrushConverter _brushConverter = new BrushConverter();

        #endregion

        #region Constructor

        public SecondLevelMenuBtn()
        {
            InitializeComponent();
            IsChecked = false;
            this.MouseLeftButtonUp += SecondLevelMenuBtn_MouseLeftButtonUp;
            MouseLeave += SecondLevelMenuBtn_MouseLeave;
            MouseMove += SecondLevelMenuBtn_MouseMove;
        }

        #endregion

        #region Properties

        public bool IsChecked
        {
            get
            {
                return _isChecked;
            }
            set
            {
                _isChecked = value;
                SetUI(value);
            }
        }

        #endregion

        #region 依赖属性

        #endregion

        #region Event

        public event EventHandler<RoutedEventArgs> Click;

        #endregion

        #region Private Methods

        private void SetUI(bool isMouseMove)
        {
            if (isMouseMove)
            {
                Brush brush = (Brush)_brushConverter.ConvertFromString("#00b1cb");
                _separator.Background = brush;
                _txtName.Foreground = brush;
                if (this.DataContext != null)
                    _img.Source = new BitmapImage(new Uri((this.DataContext as MenuListModel).Imgurl1, UriKind.Relative));
            }
            else
            {
                _separator.Background = Brushes.Transparent;
                _txtName.Foreground = (Brush)_brushConverter.ConvertFromString("#666666");
                if (this.DataContext != null)
                    _img.Source = new BitmapImage(new Uri((this.DataContext as MenuListModel).Imgurl, UriKind.Relative));
            }
        }

        #endregion

        #region Public/Protected Methods

        #endregion


        #region EventHandlers

        private void SecondLevelMenuBtn_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Click?.Invoke(this, e);
        }

        private void SecondLevelMenuBtn_MouseMove(object sender, MouseEventArgs e)
        {
            SetUI(true);
        }

        private void SecondLevelMenuBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!IsChecked)
                SetUI(false);
        }


        #endregion


    }
}
